package com.arron.algorithm.leetcodetop100.单调栈;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class 下一个更大元素 {


    public int[] nextGreaterElement(int[] nums1, int[] nums2) {

        Map<Integer, Integer> map = nextGreaterElement(nums2);

        for (int i = 0; i < nums1.length; i++) {
            nums1[i] = map.get(nums1[1]);
        }
        return nums1;
    }



    public Map<Integer,Integer> nextGreaterElement(int[] nums) {

        Stack<Integer> stack = new Stack<>();
        Map<Integer,Integer> res = new HashMap<>();
        for (int i = nums.length-1; i >= 0 ; i--) {


            while (!stack.isEmpty() && stack.peek() < nums[i]){
                stack.pop();
            }
            res.put(nums[i],stack.isEmpty()? -1: stack.peek());
            stack.push(nums[i]);
        }
        return res;
    }


    public static void main(String[] args) {
        int[] a = {1,3,4,2};

        下一个更大元素 next = new 下一个更大元素();


    }

}
